package com.leetcode.q728;

import java.util.ArrayList;
import java.util.List;

/**
 * <p> description: 自除数：可以被它包含的每一位数整除的数
 *     给定一个范围，返回范围内的自除数
 * </p>
 *
 * @author tanzc
 * @date 2022/3/31
 **/
public class SelfDividingNumbers {
    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> selfDividingNumbers = new ArrayList<>();
        for (int l = left; l <= right; l++) {
            int t = l;
            boolean flag = true;
            while (t != 0) {
                if (t % 10 == 0 || l % (t % 10) != 0) {
                    flag = false;
                    break;
                }
                t = t / 10;
            }
            if (flag) {
                selfDividingNumbers.add(l);
            }
        }
        return selfDividingNumbers;
    }

    public static void main(String[] args) {
        SelfDividingNumbers selfDividingNumbers = new SelfDividingNumbers();
        for (int i : selfDividingNumbers.selfDividingNumbers(1, 22)) {
            System.out.printf("%d ", i);
        }
    }
}
